﻿using System.Configuration;
using System.Windows.Input;

using Aliphant.Common.Managers;
using Aliphant.Datas;
using Aliphant.IoC;
using Aliphant.Mvvm.XEvent.UI;
using Aliphant.UI.Services;

namespace Aliphant.UI.Windows
{
    /// <summary>
    /// 自定义全局命令
    /// </summary>
    public static class GlobalProperty
    {
        /// <summary>
        /// 窗口拖动
        /// </summary>
        public static RoutedCommand WindowDropMoveCommand { get; } = new RoutedCommand();

        /// <summary>
        /// 窗口置顶
        /// </summary>
        public static RoutedCommand TopWindowCommand { get; } = new RoutedCommand();

        /// <summary>
        /// 主页
        /// </summary>
        public static RoutedCommand HomePageCommand { get; } = new RoutedCommand();

        /// <summary>
        /// 皮肤/主题设置
        /// </summary>
        public static UICommand<ThemeInfo> SetThemeCommand { get; } = new UICommand<ThemeInfo>((obj) =>
        {
            if (obj == null)
            {
                return;
            }

            ConfigManager.Instance.Settings.AppearanceType = (AppearanceType)obj.Id;
            var themeService = IoCServer.Container.Resolve<ThemeService>();
            themeService.ApplyTheme(obj.Id);
        });

        public static event Action<string>? NavigatedEvent;

        public static event Action<bool>? SetThemeVisibleEvent;

        public static void Navigated(string page)
        {
            NavigatedEvent?.Invoke(page);
        }

        public static void SetThemeVisible(bool visible)
        {
            SetThemeVisibleEvent?.Invoke(visible);
        }
    }
}
